import { defineStore } from "pinia";
import { ref } from "vue";

const useMenuStore = defineStore(
  "Menu",
  () => {
    const isCallapse = ref(false);
    const selectMenu = ref([]);
    const callapseMenu = () => {
      isCallapse.value = !isCallapse.value;
    };
    const addMenu = (value) => {
      if (
        selectMenu.value.findIndex((item) => item.path === value.path) === -1
      ) {
        selectMenu.value.push(value);
      }
    };
    const closeMenu = (value) => {
      const index = selectMenu.value.findIndex(
        (item) => item.name === value.name
      );
      selectMenu.value.splice(index, 1);
    };
    const menuActive = ref("1-1");
    const changeActive = (value) => {
      menuActive.value = value;
    };
    return {
      isCallapse,
      selectMenu,
      menuActive,
      callapseMenu,
      addMenu,
      closeMenu,
      changeActive,
    };
  },
  {
    persist: {
      enabled: true,
    },
  }
);
export default useMenuStore;
